package com.jnu.mydiary;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.jnu.mydiary.ui.shouye1.myBean;

import java.io.Serializable;

public class ShowActivity extends AppCompatActivity {

    private myBean mBean;
    private FloatingActionButton floatingActionButton;
    private LinearLayout mlayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        Bundle bundle = getIntent().getExtras();//在这里去处理传过来的数据
        if (bundle != null) {
            Serializable serializable = bundle.getSerializable("DataInfo");
            if (serializable != null && serializable instanceof myBean) {
                //goodsEntityList.add(new Data("111",20.0,"none",new Date(),R.drawable.home));
                mBean = (myBean) serializable;
            }
        }
        TextView date = findViewById(R.id.show_item_tv_date);
        date.setText(mBean.getDate());
        TextView title = findViewById(R.id.show_item_tv_title);
        title.setText(mBean.getTitle());
        ImageView weather = findViewById(R.id.show_iv_weather);
        weather.setImageResource(mBean.getwImageId());
        ImageView mood = findViewById(R.id.show_iv_mood);
        mood.setImageResource(mBean.getmImageId());
        TextView text = findViewById(R.id.show_item_tv_text);
        text.setText(mBean.getText());
        TextView moodtext=findViewById(R.id.tv2);
        moodtext.setText(mBean.getMood());

        mlayout = findViewById(R.id.show_item_iv_daily);
        for (int i = 0; i < mBean.getDialy().size(); i++) {
            int simageId = mBean.getDialy().get(i);
            ImageView newImg = new ImageView(this);
            //设置想要的图片，相当于android:src="@drawable/image"
            newImg.setImageResource(simageId);
            DisplayMetrics displayMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            float density = displayMetrics.density;
            LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
                    (int) (48 * density),
                    (int) (48 * density));

            //相当于android:layout_marginLeft="8dp"
            params1.leftMargin = 8;

            //addView(View child)，默认往已有的view后面添加，后插入，不设置布局params,默认wrap_content
            //mLinearLayout_dialy.addView(newImg);

            //addView(View child, LayoutParams params)，往已有的view后面添加，后插入,并设置布局
            mlayout.addView(newImg, params1);

            //addView(View view,int index, LayoutParams params),在某个index处插入
            //mLinearLayout_dialy.addView(newImg, 0, params1);
        }

    floatingActionButton=findViewById(R.id.floatingActionButton_exit_show);
        floatingActionButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}